package com.oracle.oa.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.oracle.oa.dao.MessageDao;
import com.oracle.oa.entity.Message;
import com.oracle.oa.entity.Messagetouser;
import com.oracle.oa.entity.Userinfo;

public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {

	/**
	 * 查询recordtime在某个时间段之间的message
	 */
	
	public List<Message> getByRecordtime(String begintime,String endtime) {
		List<Message> list = null;
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		Criteria c = session.createCriteria(Message.class);
		c.add(Restrictions.between("recordtime", begintime, endtime));
		list = c.list();
		session.close();
		return list;
	}

	/**
	 * 根据发件人和是否发布进行查询，得到发件箱货草稿箱的集合
	 */
	
	public List<Message> getByTouserAndIfpublish(Object userinfo, Object ifpublish) {
		List<Message> list = null;
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		Criteria c = session.createCriteria(Message.class);
		c.add(Restrictions.eq("userinfo", userinfo))
		.add(Restrictions.like("ifpublish", ifpublish));
		list = c.list();
		session.close();
		return list;
	}

	/**
	 * 查询recordtime在某个时间段之间某个部门的message
	 */
	
	public List<Message> getByRecordtimeAndDepart(Object depart,
			String begintime, String endtime) {
		List<Message> list = null;
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		Criteria c = session.createCriteria(Message.class);
		c.add(Restrictions.eq("userinfo.departid", depart))
		 .add(Restrictions.between("recordtime", begintime, endtime));
		list = c.list();
		session.close();
		return list;
	}

	/**
	 * 查询recordtime在某个时间段之间某个用户的message
	 */
	
	public List<Message> getByRecordtimeAndUser(Object user, String begintime,
			String endtime) {
		List<Message> list = null;
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		Criteria c = session.createCriteria(Message.class);
		c.add(Restrictions.eq("userinfo", user))
		 .add(Restrictions.between("recordtime", begintime, endtime));
		list = c.list();
		session.close();
		return list;
	}
	
}
